local que_lieyou = fk.CreateSkill {
    name = "que_lieyou",
    anim_type = "drawcard",
}
Fk:loadTranslationTable {
    ["que_lieyou"] = "猎诱",
    [":que_lieyou"] = "出牌阶段限一次，你可以令一名角色将手牌中一种有颜色的所有牌洗入牌堆，令其从牌堆底摸等量的牌，若其因此摸的牌颜色均相同，你可以视为使用一张普通锦囊牌或额定目标数为2的基本牌(无距离和次数限制)。",

    ["red_card"] = "红色牌",
    ["black_card"] = "黑色牌",
    ["jiben_card"] = "我要用基本牌",
    ["jinnang_card"] = "我要用锦囊牌",
}
que_lieyou:addEffect("active", {
    card_num = 0,
    target_num = 1,
    prompt = "猎诱：，你可以令一名角色制衡一个颜色的牌，有概率触发额外效果",
    can_use = function(self, player)
        return player:usedSkillTimes(que_lieyou.name, Player.HistoryPhase) == 0
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self, player, to_select, selected, cards)
        local red = #table.filter(to_select:getCardIds("h"), function(c) return Fk:getCardById(c).color == Card.Red end)
        local black = #table.filter(to_select:getCardIds("h"),
            function(c) return Fk:getCardById(c).color == Card.Black end)
        return #selected == 0 and not to_select:isKongcheng() and (red > 0 or black > 0)
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        if player:getMark("que_lieyou-phase") > 0 then
            room:setPlayerMark(player, "que_lieyou-phase", 0)
        end
        local to = effect.tos[1]
        local red = #table.filter(to:getCardIds("h"), function(c) return Fk:getCardById(c).color == Card.Red end)
        local black = #table.filter(to:getCardIds("h"), function(c) return Fk:getCardById(c).color == Card.Black end)
        local chs = { "red_card", "black_card" }
        if red == 0 then
            table.removeOne(chs, "red_card")
        end
        if black == 0 then
            table.removeOne(chs, "black_card")
        end
        local chc = room:askToChoice(player, { choices = chs, skill_name = que_lieyou.name, prompt = "猎诱：请选择要洗入牌堆的颜色" })
        local cards
        if chc == "red_card" then
            cards = table.filter(to:getCardIds("h"), function(c) return Fk:getCardById(c).color == Card.Red end)
        else
            cards = table.filter(to:getCardIds("h"), function(c) return Fk:getCardById(c).color == Card.Black end)
        end
        if chc == nil then return chc == table.random(chs) end
        table.shuffle(cards)
        local positions = {}
        local y = #room.draw_pile
        for _ = 1, #cards, 1 do
            table.insert(positions, math.random(y + 1))
        end
        table.sort(positions, function(a, b) return a > b end)
        local moveInfos = {}
        for i = 1, #cards, 1 do
            table.insert(moveInfos, {
                ids = { cards[i] },
                from = to,
                toArea = Card.DrawPile,
                moveReason = fk.ReasonJustMove,
                skillName = que_lieyou.name,
                drawPilePosition = positions[i],
            })
        end
        room:moveCards(table.unpack(moveInfos))
        if to.dead then return end
        local ids = to:drawCards(#cards, que_lieyou.name, "bottom")
        local n = 0
        for _, i in ipairs(ids) do
            if Fk:getCardById(i).color == Card.Red then
                n = n + 1
            end
        end
        if n == #cards or n == 0 then
            local choices = { "jiben_card", "jinnang_card" }
            local choice = room:askToChoice(player, { skill_name = que_lieyou.name, choices = choices })
            if choice == "jinnang_card" then
                room:askToUseVirtualCard(player, {
                    name = player:getViewAsCardNames(que_lieyou.name, Fk:getAllCardNames("t")),
                    skill_name = que_lieyou.name,
                    prompt = "猎诱：请选择要使用的锦囊牌",
                    cancelable = true,
                    extra_data = {
                        bypass_times = true,
                        bypass_distances = true,
                        extraUse = true,
                    }
                })
            else
                room:addPlayerMark(player, "que_lieyou-phase")
                room:askToUseVirtualCard(player, {
                    name = player:getViewAsCardNames(que_lieyou.name, Fk:getAllCardNames("b")),
                    skill_name = que_lieyou.name,
                    prompt = "猎诱：请选择要使用的基本牌",
                    cancelable = true,
                    extra_data = {
                        bypass_times = true,
                        bypass_distances = true,
                        extraUse = true,
                    }
                })
            end
        end
    end,
})

que_lieyou:addEffect("targetmod", {
    extra_target_func = function(self, player, skill, card)
        if player:hasSkill(que_lieyou.name) and player:getMark("que_lieyou-phase") > 0 and card and table.contains(card.skillNames, que_lieyou.name) then
            return 2
        end
    end,
})
return que_lieyou
